﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;

namespace Fulcrum.ControlGenerator
{
    public class AttachedDependencyPropertyDataContext : Fulcrum.ControlGenerator.IDependencyPropertyDataContext
    {
        ICollection<string> metadataOptions;

        public AttachedDependencyPropertyDataContext(IAttachedDependencyPropertyConfiguration config)
        {
            this.CoerceValue = config.CoerceValue;
            this.DefaultValue = config.DefaultValue;
            this.GetMethodSummary = config.GetMethodSummary;
            this.IsReadOnly = config.IsReadOnly;

            this.SetMetadataOptions(config.MetadataOptions);

            this.Name = config.Name;
            this.SetMethodSummary = config.SetMethodSummary;
            this.Type = config.Type;
            this.ValidateValue = config.ValidateValue;
            this.Visibility = config.Visibility;
        }

        public string Name
        {
            get;
            private set;
        }

        public string Type
        {
            get;
            private set;
        }

        public string DefaultValue
        {
            get;
            private set;
        }

        public bool IsReadOnly
        {
            get;
            private set;
        }

        public PropertyVisibility Visibility
        {
            get;
            private set;
        }

        public bool CoerceValue
        {
            get;
            private set;
        }

        public bool ValidateValue
        {
            get;
            private set;
        }

        public ICollection<string> MetadataOptions
        {
            get
            {
                return this.metadataOptions;
            }
        }

        private void SetMetadataOptions(ICollection<string> options)
        {
            var innerOptions = new List<string>(options);
            this.metadataOptions = new ReadOnlyCollection<string>(innerOptions);
        }

        public string DependencyPropertyName
        {
            get
            {
                return String.Format("{0}Property", this.Name);
            }
        }

        public string DependencyPropertyKeyName
        {
            get
            {
                Debug.Assert(this.IsReadOnly);
                return String.Format("{0}PropertyKey", this.Name);
            }
        }

        public string StaticChangedMethodName
        {
            get
            {
                return String.Format("{0}_PropertyChanged", this.DependencyPropertyName);
            }
        }

        public string StaticCoerceMethodName
        {
            get
            {
                return String.Format("{0}_CoerceProperty", this.DependencyPropertyName);
            }
        }

        public string StaticValidateMethodName
        {
            get
            {
                return String.Format("{0}_ValidateProperty", this.DependencyPropertyName);
            }
        }

        public string StaticPartialValidateMethodName
        {
            get
            {
                return String.Format("{0}_ValidatePropertyImplementation", this.DependencyPropertyName);
            }
        }

        public string GetMethodSummary
        {
            get;
            private set;
        }

        public string GetMethodName
        {
            get
            {
                return String.Format("Get{0}", this.Name);
            }
        }

        public string SetMethodSummary
        {
            get;
            private set;
        }

        public string SetMethodName
        {
            get
            {
                return String.Format("Set{0}", this.Name);
            }
        }
    }
}
